package com.oauth.global.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.oauth.global.client.beans.BirthdayClientBean;

public class Birthday extends Composite {

	private static BirthdayUiBinder uiBinder = GWT.create(BirthdayUiBinder.class);

	interface BirthdayUiBinder extends UiBinder<Widget, Birthday> {
	}

	@UiField
	HorizontalPanel hPanel1;

	@UiField
	HTMLPanel hPanel2AlignLeft;

	@UiField
	Image profileImage;

	@UiField
	Label birthday;

	@UiField
	Anchor name;

	private BirthdayClientBean mBirthdayClientBean;

	public Birthday(BirthdayClientBean pBirthdayBean) {
		initWidget(uiBinder.createAndBindUi(this));
		mBirthdayClientBean = pBirthdayBean;
		hPanel1.setCellHorizontalAlignment(profileImage, VerticalPanel.ALIGN_LEFT);
		hPanel1.setCellHorizontalAlignment(hPanel2AlignLeft, VerticalPanel.ALIGN_LEFT);
		profileImage.setUrl(pBirthdayBean.getPictureUrl());
		name.setText(pBirthdayBean.getName());
		birthday.setText(pBirthdayBean.getBirthday());
	}

	public void setSpacing(int spacing) {
		hPanel1.setSpacing(spacing);
	}

	public void setWidth(String width) {
		hPanel1.setWidth(width);
	}

	@UiHandler("name")
	public void onNameClick(ClickEvent e) {
		Window.open(mBirthdayClientBean.getProfileUrl(), name.getText(), null);
	}

}
